import axios from 'axios'
import router from '@/router'

// create an axios instance
const service = axios.create({
  baseURL: "http://localhost:8080", // url = base url + request url
  // withCredentials: true, // send cookies when cross-domain requests
  timeout: 5000 // request timeout
})

// 请求拦截器
service.interceptors.request.use(
  config => {
    config.headers.token = localStorage.getItem("token");
    return config;
  })

// 响应拦截器
service.interceptors.response.use(
  res=>{
    //响应403的处理
    if (res.data.data == "403") {
      router.push({path:"/403"})
    }
    return res.data;
})

export default service
